package com.easy.customer.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easy.common.bean.Customers;
import com.easy.common.bean.Product;
import com.easy.common.service.ICustomerService;
import com.easy.common.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("customer")
public class CustomerController {

    @Autowired
    ICustomerService customerService;
    @PostMapping("/")
    public ResultData insert(@RequestBody Customers customers) {
        Customers data=customerService.insert(customers);
        System.out.println(data);
        return ResultData.success(data);
    }
    @PutMapping("/")
    public ResultData update(@RequestBody Customers customers) {
        Customers data=customerService.update(customers);
        return ResultData.success(data);
    }
    @DeleteMapping("/{id}")
    public ResultData delete(@PathVariable Integer id) {
        int result=customerService.delete(id);
        if(result>=1){
            return ResultData.success("200","删除成功",null);
        }else{
            return ResultData.fail();
        }
    }
    @GetMapping("/{id}")
    public ResultData getByID(@PathVariable Integer id) {
        Customers customers=customerService.getByID(id);
        return ResultData.success(customers);
    }
    @GetMapping("/page")
    public ResultData getListByPage(IPage page, Customers customers) {
        IPage<Customers> data=customerService.getListByPage(page,customers);
        return ResultData.success(data);
    }
    @GetMapping("/list")
    public ResultData getList(Customers customers) {
        List<Customers> data=customerService.getList(customers);
        return ResultData.success(data);
    }
}
